import os
import cv2
import numpy as np


def read_file(path):
    img_list = []
    label_list = []
    dir_counter = 0
    #对路径下的所有子文件夹中的所有jpg文件进行读取并存入到一个list中
    for child_dir in os.listdir(path):
        child_path = path+"/"+child_dir
        # print(os.listdir(child_path))
        for dir_image in os.listdir(child_path):
            print(child_path+"/"+dir_image)
            Suffix_name = ['.png','.jpg','.jpeg']
            if dir_image.endswith(tuple(Suffix_name)):
                img = cv2.imread(child_path+"/"+dir_image)
                img = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
                img = cv2.resize(img,(150,150))
                img_list.append(img)
                label_list.append(dir_counter)
        dir_counter += 1
    img_list = np.array(img_list)
    return img_list,label_list,dir_counter

#读取训练数据集的文件夹，把他们的名字返回给一个list
def read_name_list(path):
    name_list = []
    for child_dir in os.listdir(path):
        name_list.append(child_dir)
    return name_list


if __name__ == '__main__':
    img_list,label_lsit,counter = read_file('train')
    print (counter)
